package com.xinyue.ext.reader.core;

import org.dom4j.Element;

import com.xinyue.ext.reader.ParamHolder;
import com.xinyue.ext.reader.bean.IdReader;
import com.xinyue.ext.reader.bean.JoinReader;
import com.xinyue.ext.reader.bean.PropertyReader;
import com.xinyue.ext.util.ListWrapper;

public class BeanManyReader {
	//参数集
	private static ParamHolder holder;

	//私有构造器
	private BeanManyReader() {
	}
	//内部类
	private static class SingletonHolder{
        private static BeanManyReader instance = new BeanManyReader();  
    }
	/**
	 * 获得对象实例
	 */
	public static BeanManyReader getInstance(ParamHolder holder) {
		BeanManyReader.holder = holder;
		//bean对象的import文件路径集合
		BeanManyReader.holder.setBeanImpt(new ListWrapper());
		return SingletonHolder.instance;
	}
	
	/**
	 * 读取many-many标签bean数据
	 */
	public void read(Element many) throws Exception {
		//读取Id标签
		IdReader.getInstance(holder).read(many);
		//读取property标签
		PropertyReader.getInstance(holder).read(many);
		//读取join标签信息
		JoinReader.getInstance(holder).joinRead(many);
		
		//set import
		holder.getEntity().setImports(holder.getBeanImpt().getList());
	}
}
